
//
//  PSegmentViewController.m
//  Project
//
//  Created by  CarlsonLee on 2019/5/29.
//  Copyright © 2019 YANJING. All rights reserved.
//

#import "PSegmentViewController.h"

@interface PSegmentViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView* table;

@end

@implementation PSegmentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    UIScrollView* scroll = [UIScrollView new];
    [self.view addSubview:scroll];
    
    self.table = [UITableView new];
    self.table.delegate = self;
    self.table.dataSource = self;
    [scroll addSubview:self.table];
    AdjustsScrollViewInsetNever(self, self.table);
    
    [scroll mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_offset(0);
        make.size.mas_equalTo(self.view);
    }];
    [self.table mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_offset(0);
        make.size.mas_equalTo(self.view);
    }];
}

#pragma mark - Delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 30;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString* identify = @"cell";
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:identify];
    if(!cell){
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identify];
    }
    cell.textLabel.text = [NSString stringWithFormat:@"cell_%ld", indexPath.row];
    return cell;
}


- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if(!self.tableCanScroll){
        self.table.contentOffset = CGPointMake(0, 0);
    }
    if(scrollView.contentOffset.y<0){
        [[NSNotificationCenter defaultCenter] postNotificationName:@"segmentDidMoveToTop" object:nil];
    }
    self.table.showsVerticalScrollIndicator = self.tableCanScroll;
}
@end
